package rothag.graphics.roulette;

import java.util.Random;

/**
 *
 * @author 
 */
public class Roulette extends Thread {

    static Random rand = new Random();
    float position = 0;
    float onenumberspeed = 300 + rand.nextInt(100);
    float onestep = 40 + rand.nextInt(10);
    int desiredValue = 0;

    public Roulette() {
        start();
    }

    @Override
    public void run() {
        long delaystep = (long) (onenumberspeed / onestep);
        float amountstep = (float) (1.0 / onestep);
        while (true) {
            synchronized (this) {
                try {
                    wait();
                } catch (InterruptedException e) {
                    System.err.println(e.getMessage());
                }
            }

            while (Math.abs(position - desiredValue) > 0.001) {
                position += amountstep;
                if (position >= 10) {
                    position = 0;
                }
                try {
                    Thread.sleep(delaystep);
                } catch (InterruptedException e) {
                    System.err.println(e.getMessage());
                }
            }

            position = desiredValue;
        }
    }

    public void setValue(int newValue) {
        desiredValue = newValue;
        synchronized (this) {
            notify();
        }
    }
}
